package org.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springmvc.entity.User;
import org.springmvc.service.UserService;
import org.springmvc.util.MsgResponse;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author tangjialin on 2016-05-31 0031.
 */
@Controller
@RequestMapping("/")
public class IndexController {

	@Resource
	private UserService userService;

	@RequestMapping
	public String index (HttpServletRequest request) {
		User user = userService.queryUser(1L);
		return "index";
	}

	@RequestMapping("/insert")
	@ResponseBody
	public MsgResponse inserUser (HttpServletRequest request) {
		MsgResponse msg = new MsgResponse();
		try {
			User user = new User();
			user = userService.inserOrUpdateUser(user);
			return msg.setData(user.getId()).setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}
}
